<?php
namespace Orm\Fabulous;

use Base\Exception\RmException;
class FabulousClass extends \Base\BaseOrmObject{
    protected   $id,
				$article_id = 0, // 文章id
				$uid = 0,
				$open_id = '',
                $is_fabulous = 0, //0已点赞 1取消点赞
				$is_del = 0, // 默认0  是否删除 1是 0否
				$insert_time = '', // 插入时间
				$update_time = ''; // 更新时间

    const FABULOUS = 0; //点赞
    const OFFFABULOUS = 1;//取消点赞

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\Fabulous\FabulousModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'article_id' => $this->article_id,
			'uid' => $this->uid,
			'is_fabulous' => $this->is_fabulous,
			'open_id' => $this->open_id,
        );

        $model = new \Orm\Fabulous\FabulousModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'article_id' => $this->article_id,
            'is_fabulous' => $this->is_fabulous,
			'uid' => $this->uid,
			'open_id' => $this->open_id,
        );

        $model = new \Orm\Fabulous\FabulousModel();
        $model->update($data, "`id` = {$this->id}");
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\Fabulous\FabulousModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }
}